import { getAreaObj, regularRule } from '@/utils/util'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/basicData/utils/index'

export const BaseFormConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'top',
	column: [
		{
			uploadTip: '服务商LOGO',
			prop: 'providerLogo',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 8,
		},
		{
			uploadTip: '统一社会信用代码证',
			prop: 'providerLicenseImg',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请输入统一社会信用代码证' }],
		},
		{
			prop: 'otherPermitImg',
			type: 'upload',
			showFileList: false,
			uploadTip: '相关资质许可证照片',
			limit: 1,
			multiple: false,
			span: 8,
		},
		{
			label: '服务商名称',
			prop: 'providerName',
			maxlength: '25',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入服务商名称' }],
			span: 8,
		},
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
			maxlength: '18',
			showWordLimit: true,
			editDisabled: true,
			rules: [
				{ required: true, message: '请输入统一社会信用代码' },
				{ pattern: regularRule.code, message: '请输入正确的统一社会信用代码' },
			],
			type: 'text',
			span: 8,
		},
		{
			label: '服务商状态',
			prop: 'providerStatus',
			propName: 'providerStatusLabel',
			type: 'remoteSelect',
			code: 'PROVIDER_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '注册地区',
			prop: 'registerArea',
			propName: 'registerAreaNames',
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择注册地区' }],
			span: 8,
		},
		{
			label: '服务商所在地区',
			prop: 'areas',
			propName: 'areasName',
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择所在地区' }],
			span: 8,
		},
		{
			label: '所在地址',
			prop: 'address',
			type: 'input',
			rules: [{ required: true, message: '请选择所在地址' }],
			span: 8,
		},

		// {
		// 	label: '服务商类别',
		// 	prop: 'providerType',
		// 	propName: 'providerTypeLabels',
		// 	type: 'remoteSelect',
		// 	code: 'PROVIDER_TYPE',
		// 	api: 'getDictItemList',
		// 	filterKey: 'value',
		// 	multiple: true,
		// 	span: 8,
		// },

		{
			label: '主营养老业务',
			prop: 'elderlyCareBusiness',
			propName: 'elderlyCareBusinessLabel',
			type: 'remoteSelect',
			code: 'ELDERLY_CARE_BUSINESS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 8,
		},

		{
			label: '开户银行',
			prop: 'bankName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},
		{
			label: '银行账号',
			prop: 'bankAccount',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},

		{
			label: '相关资质许可证名称',
			prop: 'otherPermitName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			labelPosition: 'top',
			span: 8,
		},
		{
			label: '相关资质许可证取得日期',
			prop: 'otherTermDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			labelPosition: 'top',
			span: 8,
		},
		// {
		// 	label: '统一社会信用代码证过期日期',
		// 	prop: 'licenseTermDate',
		// 	type: 'date',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD',
		// 	labelPosition: 'top',
		// 	span: 8,
		// },
		{
			label: '联系人',
			prop: 'contactUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'contactUserPhone',
			type: 'input',
			maxlength: '11',
			rules: [{ pattern: regularRule.phone, message: '请输入正确的联系方式' }],
			showWordLimit: true,
			span: 8,
		},
		{
			label: '联系人证件号码',
			prop: 'contactCardNum',
			type: 'input',
			rules: [{ pattern: regularRule.idCard, message: '请输入正确的证件号码' }],
			span: 8,
		},
		{
			label: '联系人证件类型',
			prop: 'contactCardType',
			propName: 'contactCardTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '简介',
			prop: 'providerDescribe',
			type: 'textarea',
			maxlength: '500',
			rows: 3,
			showWordLimit: true,
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '法人信息',
			span: 24,
		},
		{
			label: '法定代表人姓名',
			prop: 'deputyUserName',
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			labelPosition: 'top',
			rules: [{ required: true, message: '请输入法定代表人姓名' }],
			span: 8,
		},
		{
			label: '法定代表人联系方式',
			prop: 'deputyUserPhone',
			maxlength: '11',
			showWordLimit: true,
			type: 'text',
			rules: [
				{ required: true, message: '请输入法定代表人联系方式' },
				{ pattern: regularRule.phone, message: '请输入正确的法定代表人联系方式' },
			],
			labelPosition: 'top',
			span: 8,
		},
		// {
		// 	label: '法人登记机关',
		// 	prop: 'registerGovernment',
		// 	maxlength: '20',
		// 	showWordLimit: true,
		// 	labelPosition: 'top',
		// 	type: 'text',
		// 	span: 8,
		// },
		{
			label: '法定代表人证件类型',
			prop: 'deputyIdentifyType',
			propName: 'deputyIdentifyTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			labelPosition: 'top',
			multiple: false,
			rules: [{ required: true, message: '请选择法定代表人证件类型' }],
			span: 8,
		},
		{
			label: '法定代表人证件号码',
			prop: 'deputyIdentifyCode',
			showWordLimit: true,
			type: 'text',
			labelPosition: 'top',
			rules: [
				{ required: true, message: '请输入法定代表人证件号码' },
				{ pattern: regularRule.idCard, message: '请输入正确的法定代表人证件号码' },
			],
			span: 8,
		},

		// {
		// 	label: '法人类型',
		// 	prop: 'deputyType',
		// 	propName: 'deputyTypeLabel',
		// 	type: 'remoteSelect',
		// 	labelPosition: 'top',
		// 	code: 'DEPUTY_TYPE',
		// 	api: 'getDictItemList',
		// 	filterKey: 'value',
		// 	multiple: false,
		// 	span: 8,
		// },
		{
			label: '法人性质',
			prop: 'deputyProperty',
			propName: 'deputyPropertyLabel',
			type: 'remoteSelect',
			labelPosition: 'top',
			code: 'LEGAL_PROPERTY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			rules: [{ required: true, message: '请选择法人性质' }],
			span: 8,
		},
		{
			label: '统一社会信用代码证是否无限期',
			prop: 'isCreditCode',
			propName: 'isCreditCodeLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			rules: [{ required: true, message: '请输入统一社会信用代码证是否无限期' }],
			span: 8,
		},
		{
			label: '统一社会信用代码证有效期起始时间',
			prop: 'creditCodeStartTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请输入统一社会信用代码证有效期起始时间' }],
		},
		{
			label: '统一社会信用代码证有效期截止时间',
			prop: 'creditCodeEndTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请输入统一社会信用代码证有效期截止时间' }],
		},
		{
			label: '注册资金',
			prop: 'registeredCapital',
			type: 'input',
			isNum: true,
			append: '万元',
			// rules: [{ pattern: regularRule.number, message: '请输入正确的数量' }],
			span: 8,
		},
		{
			label: '民非组织等级',
			prop: 'organizationLevel',
			propName: 'organizationLevelLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'ORG_LEVEL',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '法人运营状态',
			prop: 'deputyState',
			propName: 'deputyStateLabel',
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
	],
}

export const detailConfig = {
	inline: false,
	labelPosition: 'left',
	labelWidth: '180px',
	column: [
		{
			prop: 'providerLicenseImg',
			span: 4,
			custome: 'carousel',
			labelPosition: 'top',
			width: '376px',
			props: ['providerLicenseImg', 'otherPermitImg'],
			style: {
				minWidth: '376px',
				height: '300px',
				borderRadius: '20px 0',
				padding: '10px',
			},
			children: [
				{
					type: 'DividerHtml',
					modelValue: '基本信息',
					position: 'center',
					labelPosition: 'top',
					span: 24,
				},
				{
					label: '服务商状态',
					prop: 'providerStatus',
					propName: 'providerStatusLabel',
					type: 'remoteSelect',
					code: 'PROVIDER_STATUS',
					api: 'getDictItemList',
					filterKey: 'value',
					multiple: false,
					span: 12,
				},
				// {
				// 	label: '服务商类别',
				// 	prop: 'providerType',
				// 	propName: 'providerTypeLabels',
				// 	type: 'remoteSelect',
				// 	code: 'PROVIDER_TYPE',
				// 	api: 'getDictItemList',
				// 	filterKey: 'value',
				// 	multiple: true,
				// 	span: 12,
				// },
				{ label: '联系人', prop: 'contactUserName', span: 12 },
				{ label: '联系方式', prop: 'contactUserPhone', span: 12 },
				{ label: '开户银行', prop: 'bankName', span: 12 },
				{ label: '银行账号', prop: 'bankAccount', span: 12 },
			],
		},
		{ label: '注册地区', prop: 'registerAreaNames', span: 8 },
		{ label: '所在地区', prop: 'areasName', span: 8 },
		{ label: '所在地址', prop: 'address', span: 8 },
		{ label: '相关资质许可证名称', prop: 'otherPermitName', span: 8 },
		{ label: '相关资质许可证取得日期', prop: 'otherTermDate', span: 8 },
		// { label: '统一社会信用代码证过期日期', prop: 'licenseTermDate', span: 8 },
		{ label: '简介', prop: 'providerDescribe', span: 24 },
		{
			type: 'DividerHtml',
			modelValue: '法人信息',
			labelPosition: 'top',
			span: 24,
		},
		{ label: '法定代表人姓名', prop: 'deputyUserName', span: 8 },
		{ label: '法定代表人联系方式', prop: 'deputyUserPhone', span: 8 },
		{ label: '法定代表人证件类型', prop: 'deputyIdentifyTypeLabel', span: 8 },
		{
			label: '法定代表人证件号码',
			prop: 'deputyIdentifyCode',
			span: 8,
		},
		// { label: '法人登记机关', prop: 'registerGovernment', span: 8 },
		// { label: '法人类型', prop: 'deputyTypeLabel', span: 8 },
		{ label: '法人性质', prop: 'deputyPropertyLabel', span: 8 },
		{ label: '民非组织等级', prop: 'organizationLevelLabel', span: 8 },
	],
	customeHeader: {
		type: 'CardOne',
		title: 'providerName',
		avatar: 'providerLogo',
		tipList: [
			{
				prop: 'providerStatusLabel',
				label: '经营状态',
				dicData: [
					{ label: '正常服务', type: 'tip-success', value: 1 },
					{ label: '停止服务', type: 'tip-error', value: 2 },
				],
			},
		],
		tagList: [{ prop: 'creditCode', type: 'success', label: '统一社会信用代码：' }],
		menuBtn: [
			{
				icon: 'delete',
				label: '删除服务商',
				type: 'danger',
				operate: 'delete',
				auth: 'view_dpServiceProvider_del',
				text: false,
				show: true,
				plain: true,
			},
		],
	},
}
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '注册地区', prop: 'registerAreaName' },
		{ label: '服务商名称', prop: 'providerName' },
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'contactUserName' },
		{ label: '联系方式', prop: 'contactUserPhone' },
		{
			label: '经营状态',
			prop: 'providerStatusLabel',
			span: 8,
		},
		// {
		// 	label: '类别',
		// 	prop: 'providerTypeLabels',
		// },
		{
			label: '详细地址',
			prop: 'address',
		},
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToReserveSearch(BaseFormConfig.column)],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(BaseFormConfig.column)],
}
export const api = {
	moreSearch: 'view_dpServiceProvider_search',
	reserveSearch: 'view_dpServiceProvider_search',
	index: 'view_dpServiceProvider_page',
	add: 'view_dpServiceProvider_gather',
	edit: 'view_dpServiceProvider_edit',
	detail: 'view_dpServiceProvider_view',
	delete: 'view_dpServiceProvider_del',
	import: 'view_dpServiceProvider_import',
	export: 'view_dpServiceProvider_export',
}
export const baseConfig = {
	pageName: '养老行业服务商',
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'providerName',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	dictcodes: [
		'ORG_LEVEL',
		'ORG_OPERATE_STATUS',
		'COMMON_FLAG',
		'ELDERLY_CARE_BUSINESS',
		'DEPUTY_TYPE',
		'PROVIDER_TYPE',
		'ID_CARD_TYPE',
		'PROVIDER_STATUS',
		'LEGAL_PROPERTY',
	],
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		index: 'view_dpServiceProvider_page',
		add: 'view_dpServiceProvider_gather',
		edit: 'view_dpServiceProvider_edit',
		detail: 'view_dpServiceProvider_view',
		delete: 'view_dpServiceProvider_del',
		import: 'view_dpServiceProvider_import',
		export: 'view_dpServiceProvider_export',
		mulitSet: 'mulitSet',
	},
	paramsObj: {
		code: 3019,
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpServiceProvider_page',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '关联养老服务组织',
			type: 'primary',
			operate: 'Associate',
			auth: 'view_dpServiceProvider_bind_org',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	moreSearchConfig,
	reserveSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '信用代码',
				prop: 'creditCode',
				type: 'input',
				span: 6,
			},
			{
				label: '名称',
				prop: 'providerName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系人',
				prop: 'contactUserName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'contactUserPhone',
				type: 'input',
				span: 6,
			},
			{
				label: '注册地区',
				prop: 'registerArea',
				type: 'AplidAreaSelect',
				span: 6,
			},
			// {
			// 	label: '服务商类别',
			// 	prop: 'providerType',
			// 	propName: 'providerTypeLabels',
			// 	type: 'remoteSelect',
			// 	code: 'PROVIDER_TYPE',
			// 	api: 'getDictItemList',
			// 	filterKey: 'value',
			// 	multiple: false,
			// 	span: 6,
			// },
			{
				label: '详细地址',
				prop: 'address',
				type: 'input',
				span: 6,
			},
			{
				label: '经营状态',
				prop: 'providerStatus',
				type: 'remoteSelect',
				code: 'PROVIDER_STATUS',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},
	detailConfig,
	tableConfig,
	beforeOnLoadFormate: async (params) => {
		const registerObj: any = getAreaObj(params.registerArea, 'register')
		params = toSearchHandle(moreSearchConfig, reserveSearchConfig, params)
		return Promise.resolve({
			...params,
			...registerObj,
			registerArea: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const registerArea: any = getAreaObj(item, 'register', 'set')
			return {
				...item,
				registerAreaNames: registerArea.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
